﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Imple.Parse;
using System.IO;

namespace TestFeed
{
    [TestFixture]
    public class TestParseTree
    {
        private ParseTree _tree;

        [TestFixtureSetUp]
        public void Init()
        {
            _tree = new ParseTree();
        }

        [Test]
        public void TestAddNode()
        {
            ParseNode node1 = new ParseNode();
            node1.Level = 0;
            node1.Value = "1";

            ParseNode node2 = new ParseNode();
            node2.Level = 0;
            node2.Value = "2";

            ParseNode node3 = new ParseNode();
            node3.Level = 1;
            node3.Value = "3";

            ParseNode node4 = new ParseNode();
            node4.Level = 1;
            node4.Value = "4";

            ParseNode node5 = new ParseNode();
            node5.Level = 0;
            node5.Value = "5";

            _tree.AddNode(node1);
            _tree.AddNode(node2);
            _tree.AddNode(node3);
            _tree.AddNode(node4);
            _tree.AddNode(node5);

            Assert.AreEqual(node1.Sibling.Sibling, node5);
        }

        private void Output(string output)
        {
            using (FileStream fs = new FileStream(@"F:\output.txt", FileMode.Create))
            {
                byte[] bs = Encoding.GetEncoding("gb2312").GetBytes(output);
                fs.Write(bs, 0, bs.Length);
            }
        }
    }
}
